<template>
  <div class="alone-outBox f14">
    <div class="alone-topBox mb16">
      <div class="flex flex-warp flex_bt">
        <div class="flex flex-warp" style="align-items:center">
          <div class="mb16">
            <span>模版名称：</span>
            <el-input v-model="searchObj.title" placeholder="请输入模版名称" class="width200 mr16" />
          </div>
          <div class="mb20">
            <el-button @click="React">重置</el-button>
            <el-button type="primary" @click="SearchListBt">筛选</el-button>
          </div>

        </div>

        <div class="realitive">
          <el-button type="primary" class="add_zj" @click="$router.push('/tool/addquestionnaire')">新增模板</el-button>
        </div>
      </div>
    </div>

    <div class="tableBox">
      <!-- 表格 -->
      <el-table v-loading="loading" :data="DataTable" style="width: 100%" max-height="620"
        :default-sort="{ prop: 'date', order: 'descending' }">
        <el-table-column prop="insCount" type="index" label="序号" min-width="100" align="left">
        </el-table-column>
        <el-table-column prop="download" label="模版类型" min-width="200" align="left">
          <template slot-scope="scope">
            <div>问卷模板</div>
          </template>
        </el-table-column>

        <el-table-column prop="templateName" label="模版名称" min-width="200" align="left">
        </el-table-column>
        <el-table-column prop="createTime" label="创建时间" min-width="200" align="left">
        </el-table-column>
        <el-table-column label="操作" align="center" width="200" fixed="right">
          <template slot-scope="scope">
            <el-button type="text" @click="editAuthor(scope.row)">修改</el-button>
            <el-button type="text" @click="deleted(scope.row)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <div class="alignRight">
        <Pagination :total="total" :page="searchObj.page" :limit="searchObj.limit" @pagination="paginations" />
      </div>
    </div>
  </div>
</template>
<script>
import Pagination from '@/components/Pagination/index.vue'
import Cookies from 'js-cookie'
import indexapi from '@/api/index'
import { changeDateFormat7 } from "@/utils/commin";
export default {
  components: {
    Pagination
  },
  data() {
    return {
      DataTable: [],
      searchObj: {
        imshowId: '',
        channel: 1,
        isDelete: 0,
        limit: 10,
        page: 1,
        title: '',

      },
      total: 0,
      loading: false,
      reasonDia: false,
      returnReason: '',
      industryTypeList: []
    }
  },
  mounted() {
    this.searchObj.imshowId = this.$store.getters.imShowId
    this.SearchList()
  },
  methods: {
    // 删除
    deleted(val) {
      this.$confirm('此操作将永久删除该模板, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          const form = {
            id: val.templateId,
            imshowId: this.$store.getters.imShowId,
            type: 1
          }
          indexapi.tool.delQuestionTemplate(form).then((res) => {
            if (res.code == 200) {
              this.$message({
                type: 'success',
                message: '删除成功!'
              })
              this.SearchList()
            }
          })
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          })
        })
    },
    // 编辑
    editAuthor(val) {
      this.$router.push({ path: '/tool/addquestionnaire', query: { mid: val.templateId } })
    },
    // 重置
    React() {
      this.searchObj = {
        imshowId: this.$store.getters.imShowId,
        limit: 10,
        page: 1,
        title: '',
        channel: 1,
        isdelete: 0
      }
      this.datatime = []
      this.SearchList()
    },
    // 查询
    SearchListBt() {
      this.searchObj.limit = 10
      this.searchObj.page = 1
      this.SearchList()
    },
    SearchList() {
      this.loading = true
      indexapi.tool.selectTemplate(this.searchObj).then((res) => {
        this.loading = false
        this.DataTable = res.data.records
        this.DataTable.forEach(item => {
          item.createTime = changeDateFormat7(item.createTime)

        });
        this.total = res.data.total
      })
    },
    // 分页
    paginations(val) {
      this.searchObj.limit = val.limit
      this.searchObj.page = val.page
      this.SearchList()
    },
    releaseInformation() {
      this.$router.push(`/content/solutionscheme/solution/addoredit`)
    }
  }
}
</script>
<style scoped>
.topButton {
  position: absolute;
  right: 20px;
  top: 16px;
}

.flex_bt {
  justify-content: space-between;
}

.icon_right {
  font-weight: 600;
  color: #0c7ff2;
  cursor: pointer;
  font-size: 18px;
}

.add_zj {
  position: absolute;
  top: 0px;
  right: 0px;
}
</style>
